//
//  JZAddFriendViewController.m
//  QuanZiChat
//
//  Created by 张洪林 on 15/11/17.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "JZAddFriendViewController.h"
#import "AddFriendViewController.h"
#import "AddGroupViewController.h"

@interface JZAddFriendViewController ()<ViewPagerDelegate,ViewPagerDataSource>
@property (nonatomic, strong) NSArray *listArray;
@property(nonatomic,strong)NSMutableArray * titleArray;
@property(nonatomic,strong)NSArray * viewControllers;
@end

@implementation JZAddFriendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    self.dataSource = self;
    
    AddFriendViewController *fVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AddFriendViewController"];
    AddGroupViewController *gVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AddGroupViewController"];
    
    self.viewControllers = @[fVC,gVC];
    [self addTitle];
    // Do any additional setup after loading the view.
}
//添加title
- (void)addTitle{
    for (int i = 0 ; i<self.listArray.count ;i++){
        NSString *title = self.listArray[i][@"name"];
        [self.titleArray addObject:title];
    }
}

//标题
- (UIView *)viewPager:(ViewPagerController *)viewPager viewForTabAtIndex:(NSUInteger)index{
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(index*50, 0, 200, 30)];
    [label setTextAlignment:(NSTextAlignmentCenter)];
    label.text = [NSString stringWithFormat:@"%@",self.titleArray[index]];
    return label;
}
//当前的viewController
- (UIViewController *)viewPager:(ViewPagerController *)viewPager contentViewControllerForTabAtIndex:(NSUInteger)index{
    return self.viewControllers[index];
}
- (NSUInteger)numberOfTabsForViewPager:(ViewPagerController *)viewPager{
    return self.viewControllers.count;
}

//懒加载
- (NSArray *)listArray
{
    if (_listArray == nil) {
        _listArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"AddFriendViewList.plist" ofType:nil]];
    }
    return _listArray;
}
- (NSMutableArray *)titleArray{
    if (!_titleArray) {
        _titleArray = [NSMutableArray new];
    }
    return _titleArray;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
